package com.ruoyi.web.controller.crm;

import com.bonuo.crm.domain.*;
import com.bonuo.crm.domain.vo.DelMore;
import com.bonuo.crm.domain.vo.PlanDto;
import com.bonuo.crm.mapper.MarketAnalysisMapper;
import com.bonuo.crm.mapper.ProvinceMapper;
import com.bonuo.crm.mapper.YearMapper;
import com.bonuo.crm.service.ClientAnalysisService;
import com.bonuo.crm.service.MarketAnalysisService;
import com.bonuo.crm.service.PlanItemService;
import com.bonuo.crm.service.PlanService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.PageUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/crm/plan")
@Api(tags = "销售计划管理")
public class PlanController extends BaseController {
    @Autowired
    private PlanService planService;

    //查询计划列表
    @GetMapping("/list")
    @ApiOperation(value = "查询计划列表",httpMethod = "GET")
    public TableDataInfo list(Plan plan,Integer pageNum,Integer pageSize) {
        if(pageNum != null && pageSize != null){
            startPage();
        }
        List<Plan> planList = planService.selectPlanList(plan);
        return getDataTable(planList);
    }

    //根据ID查询详情接口
    @ApiOperation(value = "根据ID查询详情接口",httpMethod = "GET")
    @GetMapping("/detail/{id}")
    public AjaxResult detail(@PathVariable Integer id) {
        Plan plan = planService.selectPlanContentById(id);
        return success(plan);
    }

    //添加计划
    @PostMapping("/add")
    @ApiOperation(value = "添加计划",httpMethod = "POST")
    public AjaxResult add(@RequestBody Plan plan){
        Integer add = planService.insertPlan(plan);
        return add>0?AjaxResult.success(add):AjaxResult.error();
    }

    //修改计划
    @PutMapping("/update")
    @ApiOperation(value = "修改计划",httpMethod = "PUT")
    public AjaxResult update(@RequestBody Plan plan){
        Integer update = planService.updatePlan(plan);
        return toAjax(update);
    }

    //删除计划
    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除计划",httpMethod = "DELETE")
    public AjaxResult delete(@PathVariable Integer id){
        Integer delete = planService.deletePlan(id);
        return toAjax(delete);
    }

}
